import datetime
from odoo import fields, models, api


class StockLot(models.Model):
    _inherit = 'stock.lot'

    production_date = fields.Date(string="Production date", tracking=True)
    s_week_of_year = fields.Char(string='Production Week Of Year', copy=False, tracking=True)

    s_production_id = fields.Many2one('mrp.production', 'Production', readonly=True, copy=False, index=1)

    @api.depends('product_id', 'production_date')
    def _compute_expiration_date(self):
        for lot in self:
            if lot.product_id.use_expiration_date and not lot.expiration_date:
                if not lot.production_date:
                    lot.expiration_date = False
                    continue
                duration = lot.product_id.product_tmpl_id.expiration_time
                lot.expiration_date = lot.production_date + datetime.timedelta(days=duration)
